package model;

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.util.HashMap;

/**
 * The Class ImageLayers.
 * @author Dmitry
 */
public class ImageLayers {

	/** The time stamp. */
	private String timeStamp;
	
	/** The location. */
	private int location;
	
	/** The image. */
	private BufferedImage image;
	
	/** The new image. */
	private BufferedImage newImage;
	
	/** The layers - contains all layer that a photo has */
	private HashMap<String, BufferedImage> layers = new HashMap<String, BufferedImage>();
	
	
	/**
	 * Instantiates a new image layers.
	 *
	 * @param timeStamp the time stamp
	 * @param location the location
	 * @param img the img
	 */
	public ImageLayers(String timeStamp,int location,BufferedImage img){
		this(timeStamp,location,img,null,null);
	}
	
	/**
	 * Instantiates a new image layers.
	 *
	 * @param timeStamp the time stamp
	 * @param location the location
	 * @param img the img
	 * @param layerName the layer name
	 * @param layer the layer
	 */
	public ImageLayers(String timeStamp,int location,BufferedImage img,String layerName,BufferedImage layer){
		this.timeStamp = timeStamp;
		this.location = location;
		this.image = copyImage(img);
		this.newImage =  copyImage(img);
		layers.put(layerName, layer);
	}
	
	/**
	 * Gets the layer.
	 *
	 * @param name the name
	 * @return the layer
	 */
	public BufferedImage getLayer(String name){
		return layers.get(name);
	}
	
	/**
	 * Sets the layer.
	 *
	 * @param name the name
	 * @param layer the layer
	 */
	public void setLayer(String name ,BufferedImage layer)
	{
		layers.put(name, layer);
	}
	
	/**
	 * Gets the image.
	 *
	 * @return the image
	 */
	public BufferedImage getImage() {
		return image;
	}

	/**
	 * Sets the image.
	 *
	 * @param image the new image
	 */
	public void setImage(BufferedImage image) {
		this.image = image;
	}

	/**
	 * Gets the time stamp.
	 *
	 * @return the time stamp
	 */
	public String getTimeStamp() {
		return this.timeStamp;
	}

	/**
	 * Sets the time stamp.
	 *
	 * @param timeStamp the new time stamp
	 */
	public void setTimeStamp(String timeStamp) {
		this.timeStamp = timeStamp;
	}

	/**
	 * Gets the location.
	 *
	 * @return the location
	 */
	public int getLocation() {
		return this.location;
	}

	/**
	 * Sets the location.
	 *
	 * @param location the new location
	 */
	public void setLocation(int location) {
		this.location = location;
	}

	/**
	 * Gets the new image.
	 *
	 * @return the new image
	 */
	public BufferedImage getNewImage() {
		return this.newImage;
	}

	/**
	 * Sets the new image.
	 *
	 * @param newImage the new new image
	 */
	public void setNewImage(BufferedImage newImage) {
		this.newImage = copyImage(newImage);
	}
	
	/**
	 * Copy image - creates a new copy of the original image.
	 *
	 * @param img - the original img we want to create a copy of.
	 * @return the new copy of buffered image
	 */
	private BufferedImage copyImage(BufferedImage img){
		BufferedImage temp = new BufferedImage(img.getWidth(), img.getHeight(), img.getType());
	    Graphics g = temp.getGraphics();
	    g.drawImage(img, 0, 0, null);
	    g.dispose();
	    return temp;
	}
}
